import type { VbenFormSchema } from '#/adapter/form';
import type { OnActionClickFn, VxeTableGridOptions } from '#/adapter/vxe-table';
import type { BpmModelApi } from '#/api/bpm/model';

import { DICT_TYPE } from '@vben/constants';

/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'name',
      label: '模型名称',
      component: 'Input',
      componentProps: {
        placeholder: '请输入模型名称',
        allowClear: true,
      },
    },
    {
      fieldName: 'code',
      label: '分类标志',
      component: 'Input',
      componentProps: {
        placeholder: '请输入分类标志',
        allowClear: true,
      },
    },
  ];
}
/** 列表的字段 */
export function useGridColumns(
  onActionClick?: OnActionClickFn<BpmModelApi.Model>,
): VxeTableGridOptions<BpmModelApi.Model>['columns'] {
  return [
    {
      field: 'name',
      title: '流程名称',
      minWidth: 200,
      slots: { default: 'name' },
    },
    {
      field: 'startUserIds',
      title: '可见范围',
      minWidth: 150,
      slots: { default: 'startUserIds' },
    },
    {
      field: 'type',
      title: '流程类型',
      minWidth: 120,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_TYPE.BPM_MODEL_TYPE },
      },
    },
    {
      field: 'formType',
      title: '表单信息',
      minWidth: 150,
      slots: { default: 'formInfo' },
    },
    {
      field: 'deploymentTime',
      title: '最后发布',
      minWidth: 280,
      slots: { default: 'deploymentTime' },
    },
    {
      align: 'center',
      cellRender: {
        attrs: {
          nameField: 'name',
          nameTitle: '流程模型',
          onClick: onActionClick,
        },
        name: 'CellOperation',
        options: [
          {
            code: 'edit',
            type: 'primary',
            title: '修改',
          },
          {
            code: 'publish',
            type: 'primary',
            title: '发布',
          },
          {
            code: 'copy',
            type: 'primary',
            title: '复制',
          },
          {
            code: 'history',
            type: 'primary',
            title: '历史',
          },
          {
            code: 'report',
            type: 'primary',
            title: '报表',
          },
          {
            code: 'clear',
            type: 'primary',
            title: '清理',
          },
          {
            code: 'delete',
            type: 'danger',
          },
        ],
      },
      field: 'operation',
      fixed: 'right',
      headerAlign: 'center',
      showOverflow: false,
      title: '操作',
      width: 200,
    },
  ];
}
